package com.beeway.blackgoose.utils;

import android.os.CountDownTimer;
import android.widget.Button;
import android.widget.TextView;

import com.beeway.blackgoose.R;

/**
 * @说 明：
 * @项目名称：BlackGoose
 * @包 名： com.beeway.blackgoose.utils
 * @类 名：
 * @创 建人：chenshuangniu
 * @创建时间：2015 2015/9/22
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注： 一个手机短信验证倒计时
 */

public class MyCountTimer extends CountDownTimer {
    public static final int TIME_COUNT = 121* 1000;//防止从59开始显示
    private TextView btn;
    private int endStreRid;
    private int normalColor, timingColor;

    public MyCountTimer(long millisInFuture, long countDownInterval, Button btn, int endStreRid) {
        super(millisInFuture, countDownInterval);
        this.btn = btn;
        this.endStreRid = endStreRid;
    }

    public MyCountTimer(TextView btn, int endStreRid) {
        super(TIME_COUNT, 1000);
        this.btn = btn;
        this.endStreRid = endStreRid;
    }

    public MyCountTimer(TextView btn) {
        super(TIME_COUNT, 1000);
        this.btn = btn;
        this.endStreRid = R.string.get_msg_code;
    }

    public MyCountTimer(TextView tv, int normalColor, int timingColor) {
        this(tv);
        this.normalColor = normalColor;
        this.timingColor = timingColor;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        if (timingColor > 0) {
            btn.setTextColor(timingColor);
        }
        btn.setEnabled(false);
        btn.setText(millisUntilFinished / 1000 + "s" + "后重新发送");
    }

    @Override
    public void onFinish() {
        if (normalColor > 0) {
            btn.setText(endStreRid);
        }
        btn.setText(endStreRid);
        btn.setEnabled(true);
    }
}
